<template>
  <div id="app">
    <el-card v-if="!hasInit">
      {{ messages.loading }}
    </el-card>
    <url-set @url-set="showSetUrl = false" v-if="hasInit && (!rules || showSetUrl)"/>
    <div v-if="rules && !showSetUrl" class="main-content">
      <el-tabs type="border-card">
        <el-tab-pane :label="messages.title1">
          <rules/>
        </el-tab-pane>
        <el-tab-pane :label="messages.title3">
          <special-list/>
        </el-tab-pane>
        <el-tab-pane :label="messages.title2">
          <setting @change-proxy="showSetUrl = true"/>
        </el-tab-pane>
      </el-tabs>
      <div class="more-settings">
        <div class="label">
          <div>{{ messages.enable }}</div>
          <div>{{ messages.tip_enable }}</div>
        </div>
        <el-switch v-model="proxyEnabled" @change="setProxyStatus"></el-switch>
      </div>
    </div>
  </div>
</template>
<script setup>
import {proxyEnabled, hasInit, rules, init, getProxyStatus} from './uses/useInit.js';
import {messages} from './uses/useI18nMessage.js';
import {onMounted, ref} from 'vue';
import UrlSet from './components/url-set.vue';
import Rules from './components/rules.vue';
import Setting from './components/setting.vue';
import {reload} from './uses/useUtils.js';
import SpecialList from './components/special-list.vue';
import {bProxy, bContextMenu} from './api';

const setProxyStatus = async (value) => {
  value ? await bProxy.enable() : await bProxy.disable();
  await getProxyStatus();
  await reload();
  await bContextMenu.setMenu();
};
const showSetUrl = ref(false);
onMounted(() => {
  init();
});
</script>
<style lang="scss">
.link {
  color: #409EFF;
  text-decoration: none;
  cursor: pointer;
}

body {
  padding: 0;
  margin: 0;
  width: 350px;
  font: 14px/1.5 "Source Sans Pro", "Helvetica Neue", Arial, sans-serif;
}

#app {
  background: #ffffff;
  overflow: auto;
}

.content {
  padding: 0 5px;
}

.help {
  color: #aaaaaa;
}

.help-inline {
  margin-left: 5px;
  color: #aaaaaa;
}

.el-form-item {
  margin-bottom: 5px !important;
}

.el-form-item__label {
  text-align: left;
}

.main-content {
  position: relative;
  padding-bottom: 50px;

  .el-tabs__header {
    margin-bottom: 0;

    .el-tabs__item {
      font-size: 16px !important;
      font-weight: bold;
    }
  }

  .el-tabs__content {
    max-height: 400px;
    overflow: auto;
    padding-bottom: 20px;
  }
}

.more-settings {
  height: 50px;
  display: flex;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  align-items: center;
  padding: 0 20px;
  background: #ffffff;
  border-top: 1px solid #efefef;
  box-shadow: 0 -1px 5px rgba(0, 0, 0, 0.2);
  z-index: 100;

  .label {
    flex: 1;

    > div {
      font-size: 12px;
      color: #999;

      &:first-child {
        font-size: 14px;
        color: #333;
        font-weight: bold;
      }
    }
  }
}
</style>
